home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 58517 / 58517.xpi / vexpand.jar / content / vexpand.js < prev   
Text File  |  2010-01-09  |  4KB  |  113 lines

  1. var vexpand = {id:function(id){
  2.                     return document.getElementById(id);
  3.                 },
  4.            init:function(){
  5.                 try{
  6.                     var oContext = vexpand.id("contentAreaContextMenu");
  7.                     oContext.setAttribute("onpopupshowing", "vexpand.contextShowing(event); "+ oContext.getAttribute("onpopupshowing"));
  8.                 } catch(err) { alert(err); }
  9.            },
  10.            go:function(str){
  11.                 opener.focus();
  12.                 self.focus();
  13.                 if(opener.gBrowser.addTab) {
  14.                     opener.gBrowser.selectedTab = opener.gBrowser.addTab(str);
  15.                 } else {
  16.                     window.open(str);
  17.                 }
  18.            },
  19.            getLinkInfo:function(link){
  20.                 window.openDialog('chrome://vexpand/content/linkinfo.xul','VexpandLinkInfo','chrome, centerscreen, resizable', link);
  21.            },
  22.            clip:function(str, len){
  23.                 if(str.length > len) return str.substr(0, len)+"...";
  24.                 return str;
  25.            },
  26.            addUrlLabel:function(field, str, url){
  27.                 field.setAttribute("value", str);
  28.                 if(url){
  29.                     field.setAttribute("style", "color: #00F; text-decoration: underline; cursor: pointer;");
  30.                     field.setAttribute("title", url);
  31.                     field.setAttribute("onclick", "vexpand.go('" + url + "');");
  32.                 }else{
  33.                     field.innerHTML = str;
  34.                 }
  35.            },
  36.            getLink:function(){
  37.                 if(gContextMenu != null && (gContextMenu.getLinkURL || gContextMenu.linkURL)){    
  38.                     return (gContextMenu.getLinkURL) ? gContextMenu.getLinkURL() : gContextMenu.linkURL;
  39.                 }
  40.                 return false;
  41.            },
  42.            copyCurrentAnchor:function(){
  43.                 var url = vexpand.getLink();
  44.                 if(url){
  45.                     vexpand.copyLongUrl(url);
  46.                 }
  47.            },
  48.            copyText:function(str){
  49.                 try {
  50.                     var clipboard = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper);
  51.                     clipboard.copyString(str);        
  52.                 } catch(err) {alert(err);}
  53.            },
  54.            contextShowing:function(event){
  55.                 try{
  56.                     if(document.popupNode.nodeName.toUpperCase() == "A"){
  57.                         vexpand.id("vexpand-context-link-menu").setAttribute("collapsed", false);
  58.                         vexpand.id("vexpand-copy-link-menu").setAttribute("collapsed", false);
  59.                     } else {
  60.                         vexpand.id("vexpand-context-link-menu").setAttribute("collapsed", true);
  61.                         vexpand.id("vexpand-copy-link-menu").setAttribute("collapsed", true);
  62.                     }
  63.                 } catch(err) {alert(err);}
  64.            },
  65.            getShortUrl:function(str){
  66.                 var vexpandDom = {};
  67.                 try{
  68.                     var request    = new XMLHttpRequest();
  69.                     request.open( 'GET', 'http://api.voizle.com/expand?format=xml&u=' + str, false);  
  70.  
  71.                     request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  72.                     request.send(null);
  73.  
  74.                     var vzdom = request.responseXML;
  75.                     vexpandDom['shorturl'] = vzdom.getElementsByTagName('shorturl').item(0).childNodes[0].nodeValue;
  76.                     vexpandDom['longurl'] = vzdom.getElementsByTagName('longurl').item(0).childNodes[0].nodeValue;
  77.                     vexpandDom['success'] = true;
  78.                 }catch(e){
  79.                     vexpandDom['success'] = false;
  80.                 }
  81.                 return vexpandDom;
  82.            },
  83.            copyLongUrl:function(str){
  84.                 try{
  85.                     var vexpandUrl = vexpand.getShortUrl(str);
  86.                     if(vexpandUrl.success){
  87.                         vexpand.copyText(vexpandUrl.longurl);
  88.                     }
  89.                 }catch(e){
  90.                     vexpand.copyText('http://www.voizle.com/');
  91.                 }
  92.            }
  93.     }
  94.  
  95. function v_expand(link) {
  96.     try{
  97.         var longurl  = vexpand.id("longurl");
  98.         var shorturl = vexpand.id("shorturl");
  99.         
  100.         var url = 'http://www.voizle.com';
  101.         
  102.         if(link && window.arguments[0]){
  103.             url = window.arguments[0];
  104.         }
  105.         
  106.         var urlInfo = vexpand.getShortUrl(url);
  107.         if(urlInfo.success){
  108.             vexpand.addUrlLabel(longurl, urlInfo.longurl, urlInfo.longurl);
  109.             vexpand.addUrlLabel(shorturl, vexpand.clip(urlInfo.shorturl, 30), urlInfo.shorturl);
  110.         }
  111.     }catch(e){alert(vexpand.id('vexpand_strings').getString('VExpand.noconnection'));}
  112. }
  113.